﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public partial class player
    {
        public int Rank { get; set; }
        /// <summary>
        /// 专家平均分
        /// </summary>
        public decimal ExpertScore
        {
            get
            {
                decimal score = 0.00M;
                if (id > 0)
                {

                    scorelogLogic sl = new scorelogLogic();
                    scoresettingLogic setl = new scoresettingLogic();
                    var scoreSetting = setl.Getscoresetting(new scoresetting());
                    var logs = sl.Getscorelogs(new scorelog { playerid = id, type = (int)UserType.Expert }, "", "score", "desc");
                    if (logs.Count > 0)
                    {
                        if (logs.Count > 2)
                        {
                            //如果去除最高分和最低分
                            if (scoreSetting.isexcludeminandmax)
                            {
                                logs.Remove(logs[0]); //删除最高分
                                logs.Remove(logs[logs.Count - 1]); //删除最低分
                            }
                            score = logs.Average(o => (decimal)o.score);
                        }
                        else
                        {
                            score = logs.Average(o => (decimal)o.score);

                        }
                    }
                }
                return Math.Round(score, 2); ;
            }
        }
        public string ExpertScoreStr
        {
            get
            {
                return ExpertScore.ToString("0.00");
            }
        }

        /// <summary>
        /// 大众平均分
        /// </summary>
        public decimal PublicScore
        {
            get
            {
                decimal score = 0.00M;
                if (id > 0)
                {
                    scorelogLogic sl = new scorelogLogic();
                    var logs = sl.Getscorelogs(new scorelog { playerid = id, type = (int)UserType.Public }, "", "score", "desc");
                    if (logs.Count > 0)
                    {
                        score = logs.Average(o => (decimal)o.score);
                    }
                }
                return Math.Round(score, 2); ;
            }
        }
        public string PublicScoreStr
        {
            get
            {
                return PublicScore.ToString("0.00");
            }
        }

        /// <summary>
        /// 总平均分
        /// </summary>
        public decimal TotalScore
        {
            get
            {
                decimal score = 0.00M;
                if (id > 0)
                {
                    scoresettingLogic setl = new scoresettingLogic();
                    var scoreSetting = setl.Getscoresetting(new scoresetting());
                    //大众分* 大众百分比+专家分 * 专家百分比。
                    score = ExpertScore * scoreSetting.expertpercent / 100 + PublicScore * (100 - scoreSetting.expertpercent) / 100;
                }
                return Math.Round(score, 2); ;
            }
        }

        public string TotalScoreStr
        {
            get
            {
                return TotalScore.ToString("0.00");
            }
        }
    }
}
